package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mywood.R;
import com.youth.banner.loader.ImageLoader;

import java.util.List;
import java.util.Map;

import bean.GoodsShaixuanBean;
import bean.ShaixuanBean;


public class ShaixuanAdapter extends BaseAdapter {


    private int checkitem;
    private String type;
    private List<String> clickids;
    private Context context;
    private LayoutInflater mInflater;
    List<GoodsShaixuanBean.DataBean.AttrListBean> mData;

    public ShaixuanAdapter(Context context){
        this.mInflater = LayoutInflater.from(context);
    }

    public ShaixuanAdapter(Context context, List<GoodsShaixuanBean.DataBean.AttrListBean> mData){
        this.context=context;
        this.mInflater = LayoutInflater.from(context);
        this.mData=mData;


    }
    public void setData(List<GoodsShaixuanBean.DataBean.AttrListBean> mData,int checkitem,String type,List<String> clickids){
        this.mData=mData;
        this.checkitem=checkitem;
        this.type=type;
        this.clickids=clickids;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {

            holder=new ViewHolder();

            convertView = mInflater.inflate(R.layout.item_shaixuanone, null);

            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.img_check = (ImageView) convertView.findViewById(R.id.img_check);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.tv_name.setText(mData.get(position).getAttr_value());
        boolean ischeck = false;
        for (int m = 0;m<clickids.size();m++){
            String idson = mData.get(position).getId()+"";
            String idfu = mData.get(position).getKind_id()+"";
            String s = clickids.get(m);
            String[] split = s.split("=");
            if (idson.equals(split[0]) && idfu.equals(split[1])){
                ischeck = true;
                break;
            }


            /*if (splitIds[m].equals(mData.get(position).getId()+"")){
                ischeck = true;
                break;
            }*/
        }

        if (ischeck){
            holder.img_check.setVisibility(View.VISIBLE);
            holder.tv_name.setTextColor(context.getResources().getColor(R.color.colordorange));
        }else{
            holder.img_check.setVisibility(View.GONE);
            holder.tv_name.setTextColor(context.getResources().getColor(R.color.color333));
        }



        return convertView;
    }

    public static class ViewHolder{

        ImageView img_check ;
        TextView tv_name ;



    }


}